package com.example.administrator.test.order;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

import com.example.administrator.test.R;

/**
 * Created by Administrator on 2017/1/7.
 */
public class CancelReasonActivity extends AppCompatActivity {
    private String mCancelReason1, mCancelReason2,mCancelReason3,mCancelReason4,
            mCancelReasonOther, mCancelReasonAll;
    private CheckBox mCancelReasonCheck1,mCancelReasonCheck2,mCancelReasonCheck3,mCancelReasonCheck4,checkBox;
    private TextView mCancelText1,mCancelText2,mCancelText3,mCancelText4;
    private EditText mCancelReasonEditText;
    private Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            msg.what=1;
        }
    };
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_canceltheorder);
        mCancelReasonCheck1= (CheckBox) findViewById(R.id.cancelReasonCheck1);
        mCancelReasonCheck2= (CheckBox) findViewById(R.id.cancelReasonCheck2);
        mCancelReasonCheck3= (CheckBox) findViewById(R.id.cancelReasonCheck3);
        mCancelReasonCheck4= (CheckBox) findViewById(R.id.cancelReasonCheck4);
        mCancelReasonEditText= (EditText) findViewById(R.id.cancelReasonOther);
        mCancelText1= (TextView) findViewById(R.id.cancelText1);
        mCancelText2= (TextView) findViewById(R.id.cancelText2);
        mCancelText3= (TextView) findViewById(R.id.cancelText3);
        mCancelText4= (TextView) findViewById(R.id.cancelText4);
        //判断哪个输入框的
        if (mCancelReasonCheck1.isChecked()){
            mCancelReason1= mCancelText1.getText().toString();
        }
        if (mCancelReasonCheck2.isChecked()){
            mCancelReason2 = mCancelText2.getText().toString();
        }
        if (mCancelReasonCheck3.isChecked()){
            mCancelReason3= mCancelText3.getText().toString();
        }
        if (mCancelReasonCheck4.isChecked()){
            mCancelReason4= mCancelText4.getText().toString();
        }
        mCancelReasonOther=mCancelReasonEditText.getText().toString();
        mCancelReasonAll=mCancelReason1+mCancelReason2+mCancelReason3+mCancelReason4+mCancelReasonOther;
        Message message=new Message();
        message.obj=mCancelReasonAll;
        handler.sendMessage(message);
    }
    public void checkboxChang(final CheckBox checkBox, final SendReasonListener sendReasonListener){
        checkBox.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String reason=checkBox.getText().toString();
                sendReasonListener.sendReason(reason);
            }
        });
    }
    interface SendReasonListener{
        void sendReason(String reason);
    }
}
